<!-- signature.vue -->
<template>
	<view class="dashed-box">
		<view   v-if="showSign" class="container">
			<view class="custom-title">
				<text class="label-text">{{ label }}</text>
				<signInput  :initialImage="signImage" @signToUrl="handleSign" />
			</view>

		</view>
		
		<stampSection   v-if="showStamp"  @stamp-click="handleStampClick" />
		<view class="custom-dateText">
			<text @click="handleDateClick" class="custom-text3">{{ date || '选择日期' }}</text>
		</view>
		
		  
		<!-- 日期选择弹窗 -->
		<uni-popup ref="datePopup" type="dialog">
			<uni-popup-dialog mode="base" title="选择日期" @confirm="handleDialogConfirm" @close="handleDialogClose">
				<uni-datetime-picker type="date" :value="date" @change="handleDateChange" />
			</uni-popup-dialog>
		</uni-popup>
	</view>
</template>

<script>
	import signInput from "@/components/am-sign-input/am-sign-input.vue"
import stampSection from '@/components/order/stamp-section.vue'
	export default {
		components: {
			signInput,stampSection
		},
		props: {
			label: {
				type: String,
				default: '签名项'
			},
			signImage: {
				type: String,
				default: ''
			},
			date: {
				type: String,
				default: ''
			},showStamp: {
    type: Boolean,
    default: false
  },showSign: {
    type: Boolean,
    default: true
  }
		},
		data() {
			return {
				tempDate: ''
			}
		},
		methods: {
			handleSign(e) {
				console.log(e)
				const response = JSON.parse(e.data)
				console.log(response)
				this.$emit('update:signImage', response.data)
			},
			handleDateClick() {
				this.tempDate = this.date
				this.$refs.datePopup.open()
			},
			handleDateChange(value) {
				this.tempDate = value
			},
			handleDialogConfirm() {
				if (this.tempDate) {
					this.$emit('update:date', this.tempDate)
				}
				this.$refs.datePopup.close()
			},
			handleDialogClose() {
				this.tempDate = ''
				this.$refs.datePopup.close()
			}
		}
	}
</script>

<style scoped>
	/* 虚线容器 */
	.dashed-box {
		width: 100%;
		margin: 24rpx auto;
		padding: 12rpx;
		border: 2rpx dashed #333;
		border-radius: 10rpx;
		background: #fff;
		position: relative;

		&+.dashed-box {
			margin-top: 28rpx;
		}
	}

	.container {
		width: 100%;
		display: flex;
		padding-top: 20px;
		justify-content: center;
		align-items: center;
	}

	.custom-dateText {
		display: flex;
		margin: 20px;
		justify-content: flex-end;
		/* 子元素居左 */
	}

	sign-input {
		flex-grow: 1;
		/* 占据剩余宽度 */
		max-width: 80%;
		/* 防止过度拉伸 */
	}

	.custom-title {
		display: flex;
		justify-content: center;
		/* 主轴居中 */
		align-items: center;
		/* 交叉轴居中 */
		width: 100%;
		/* 确保占满父容器 */
	}
.label-text {
	text-align: left;
	padding-right: 10px;
	font-size: 16px;
  min-width: 100px;     /* 设置最小宽度保障占位 */
  max-width: 40%;       /* 限制最大宽度防止过度扩张 */
}
	/* 签名输入框 */
	.sign-input {
		height: 150px !important;
		width: calc(100% - 145px) !important;
		border: 1px solid #e0e0e0;
		border-radius: 8px;
		background: #f8f9fa !important;
		transition: all 0.3s ease;
	}

	.sign-input:hover {
		box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
	}


	.custom-text3 {
		padding-left: 10px;
		color: #0055ff;
		font-size: 16px;

		font-weight: bold;
		padding-right: 10px;

	}

	.date-text {
		color: #0055ff;
		font-size: 14px;
		font-weight: 500;
		padding: 8px 16px;
		border-radius: 6px;
		background: #f0f4ff;
		transition: all 0.2s ease;
		cursor: pointer;
	}

	.date-text:hover {
		background: #e1e9ff;
		transform: translateY(-1px);
	}

	/* 深度样式穿透 */
	:deep(.signature-canvas) {
		background: #f8f8f8 !important;
		border-radius: 6px;
	}

	/* 弹窗样式调整 */
	:deep(.uni-popup-dialog) {
		border-radius: 12px !important;
		padding: 20px !important;
	}

	:deep(.uni-datetime-picker) {
		margin: 15px 0;
	}
</style>